package tcu.iot.gasmanage.api;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import tcu.iot.gasmanage.common.Result;
import tcu.iot.gasmanage.common.utils.QuerySwitchUtils;
import tcu.iot.gasmanage.entity.datatable.DataTableQuery;
import tcu.iot.gasmanage.service.DataTableService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(value = "设备信息管理控制器")
@RestController
@RequestMapping("/dataTable")
@CrossOrigin
public class DataTableController {

    //注入dateTableService
    @Resource
    private DataTableService dataTableService;

    @ApiOperation(value = "/list", notes = "获取所有选项")
    @GetMapping(value = "/list")
    public Result sendPostRequest(HttpServletRequest request) {
        DataTableQuery dataTableQuery = JSON.parseObject(QuerySwitchUtils.QuerySwitch(request.getQueryString()), DataTableQuery.class);

        return dataTableService.GetEquipmentInfo(dataTableQuery);
    }

    @ApiOperation(value = "/options", notes = "获取所有选项")
    @PostMapping(value = "/options")
    public Result getOptions() {
        return dataTableService.FindOptions();
    }
}
